package com.test.springboot.service;

import com.test.springboot.config.UserStreams;
import com.test.springboot.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;
import org.springframework.util.MimeTypeUtils;

/**
 * @author chenxubing
 * @version $Id: UserService.java, v 0.1 2018-11-09 3:22 PM chenxubing Exp $$
 */
@Slf4j
@Component
public class UserService {
    @Autowired
    private UserStreams userStreams;

    public void send(final User user) {
        log.info("Sending user {}", user);
        MessageChannel messageChannel = userStreams.outputChannel();
        messageChannel
                .send(MessageBuilder.withPayload(user)
                .setHeader( MessageHeaders.CONTENT_TYPE,MimeTypeUtils.APPLICATION_JSON)
                .build());
    }
}
